﻿using NUnit.Framework;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;

namespace TypeResolve.Tests
{
	[TestFixture]
	class test_TypeUtils
	{
		[Test]
		public void AssembliesAreLoadedCorrectly()
		{
			//Act
			var assemblies = TypeUtils.LoadCurrentAssemblies();

			//Assert
			Assert.That(assemblies, Contains.Item(Assembly.GetExecutingAssembly()));
			Assert.That(assemblies, Contains.Item(typeof(TypeUtils).Assembly));
		}

		[Test]
		public void SearchForUnknownTypeDoesntAddDuplicateAssembliesToTheList()
		{
			try
			{
				TypeUtils.Initialize();
				var type = TypeUtils.SearchType("*unknowntype*");
				if (type == null)
					Console.WriteLine("type was not found as expected");
			}
			catch (Exception)
			{
			}

			foreach (var asm in TypeUtils.CurrentAssemblies)
			{
				Console.WriteLine(asm.FullName);
			}

			Assert.That(TypeUtils.CurrentAssemblies.Count(),
				Is.EqualTo(TypeUtils.CurrentAssemblies.Select(a => a.FullName).Distinct().Count()));
		}
	}
}
